package com.mark.mall.admin.platform.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mark.mall.admin.platform.dto.PageParamDTO;
import com.mark.mall.admin.platform.dto.param.MemberAddParam;
import com.mark.mall.admin.platform.dto.param.MemberUpdateParam;
import com.mark.mall.admin.platform.entity.Member;
import com.mark.mall.common.resultBean.R;
import com.mark.mall.admin.platform.service.MemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 会员表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-02-28
 */
@RestController
@RequestMapping("/admin/member")
@Api(tags = "后台会员模块")
@RequiredArgsConstructor
public class MemberController {

    private final MemberService memberService;

    @ApiOperation(value = "获取会员列表（查询条件：名字、手机号）", httpMethod = "GET")
    @GetMapping("list")
    public R<IPage<Member>> memberPageInfo(PageParamDTO param, String name, String mobile) {
        return memberService.memberList(param, name, mobile);
    }

    @ApiOperation(value = "新增会员", httpMethod = "POST")
    @PostMapping("add")
    public R<Boolean> addMember(@RequestBody @Valid MemberAddParam param) {
        return memberService.addMember(param);
    }

    @ApiOperation(value = "删除会员", httpMethod = "POST")
    @PostMapping("del")
    public R<Boolean> delMember(String id) {
        return memberService.delMember(id);
    }

    @ApiOperation(value = "修改会员", httpMethod = "POST")
    @PostMapping("update")
    public R<Boolean> updateMember(@RequestBody @Valid MemberUpdateParam param) {
        return memberService.updateMember(param);
    }
}
